package com.wz.two;


import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @description:
 * @author: WZ
 * @create: 2019-02-16 14:31
 **/

public abstract class Observeable<S extends Observeable<S,O,A>,O extends Observe<S,O,A>,A> {

   protected List<O> observes;

   public Observeable(){
       observes = new CopyOnWriteArrayList<>();
   }

   public void addObserve(O observe){
       this.observes.add(observe);
   }

   public void removeObserve(O observe){
       this.observes.remove(observe);
   }

   public void notifyObservers(A argument){
       for (Observe observe : observes){
           observe.update(this,argument);
       }
   }

}
